package moc.zard.xg.service.impl;

import moc.zard.xg.Repository.IUserD;
import moc.zard.xg.pojo.User;
import moc.zard.xg.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.html.Option;
import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserD IUserD;

    @Override
    public List<User> getUserListByUsername(String username) {
        List<User> userListByUsername = IUserD.findAllByUsernameEquals(username);
        return userListByUsername;
    }

    @Override
    public User insertUser(User user) {
        return IUserD.saveAndFlush(user);
    }

    @Override
    public User login(String username, String password) {
        List<User> list = IUserD.findAllByUsernameEqualsAndPasswordEquals(username, password);
        if (list.size() > 0){
            return list.get(0);
        }else {
            return null;
        }

    }
}
